import sys
import os
import xbmc
import xbmcaddon
import re
import string
import urllib
import urllib2
from urllib2 import URLError

# disgracefully stolen from xbmc subtitles
try:
    # Python 2.6 +
    from hashlib import sha as sha
except ImportError:
    # Python 2.5 and earlier
    import sha

__settings__ = xbmcaddon.Addon(id='script.soundway')
__language__ = __settings__.getLocalizedString
__version__ = "0.1.3"
__cwd__ = __settings__.getAddonInfo('path')

bNotify = False
if (__settings__.getSetting( "NotifyOnSubmit" ) == 'true'): bNotify = True

#Path handling
LANGUAGE_RESOURCE_PATH = xbmc.translatePath( os.path.join( __cwd__, 'resources', 'language' ) )
CONFIG_PATH = xbmc.translatePath( os.path.join( __cwd__, 'resources', 'settings.cfg' ) )
AUTOEXEC_PATH = xbmc.translatePath( 'special://home/userdata/autoexec.py' )
AUTOEXEC_FOLDER_PATH = xbmc.translatePath( 'special://home/userdata/' )
VERSION_PATH = xbmc.translatePath( os.path.join( __cwd__, 'resources', 'version.cfg' ) )


def Debug(message, Verbose=True):
    message = "soundway: " + message
    bVerbose = __settings__.getSetting( "debug" )
    if (bVerbose == 'true'):
        bVerbose = True
    else:
        bVerbose = False
    
    if (bVerbose and Verbose):
        # repr() is used, got wierd issues with unicode otherwise, since we send mixed string types (eg: unicode and ascii) 
        print repr(message)
    elif (not Verbose):
        # repr() is used, got wierd issues with unicode otherwise, since we send mixed string types (eg: unicode and ascii) 
        print repr(message)


def notification( header="", message="", sleep=5000, icon=__settings__.getAddonInfo( "icon" ) ):
    """ Will display a notification dialog with the specified header and message,
        in addition you can set the length of time it displays in milliseconds and a icon image. 
    """
    xbmc.executebuiltin( "XBMC.Notification(%s,%s,%i,%s)" % ( header, message, sleep, icon ) )
    